package org.test.string;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import junit.framework.Assert;

import org.apache.commons.lang.ArrayUtils;
import org.apache.log4j.Logger;
import org.apache.lucene.util.ArrayUtil;
import org.junit.Test;

public class StringCharacterTest2 {

	Logger log = Logger.getLogger(StringCharacterTest2.class);
	
	
	@Test
	public void tte() throws Exception{
//		String ENCODE = "utf-8";
//		System.out.println("参数:");
//		InputStreamReader reader = new InputStreamReader(System.in,ENCODE);
//		BufferedReader buf = new BufferedReader(reader);
//		String str = buf.readLine();
//		System.out.println(str+"原始");
//		byte[] strByte = str.getBytes("UTF8");
//		String str1 = new String(strByte,"GBK");
//		System.out.println(":"+str1+","+str1.length());
		
		
		String str = new String("这是一个123");
		byte[] strByte = str.getBytes("utf8");
		System.out.println(ArrayUtils.toString(strByte));
		String str1 = new String(strByte,"GBK");
		System.out.println(":"+str1+","+"原始");
		
//		byte[] strByte1 = str1.getBytes("utf8");
//		String str2 = new String(strByte1,"GBK");
//		System.out.println(":"+str2+","+str2.length());
		
		forEncode(str1);
	}
	
	private void forEncode(String target) throws Exception{
		String[] encodeStrArray  = {"utf8","GBK","iso-8859-1"};
		String[] decodeStrArray  = {"utf8","GBK","iso-8859-1"};
		for (int i = 0; i < encodeStrArray.length; i++) {
			String encodeStr = encodeStrArray[i];
			for (int j = 0; j < decodeStrArray.length; j++) {
				String decString = decodeStrArray[j];
				byte[] strByte1 = target.getBytes(encodeStr);
				String str2 = new String(strByte1,decString);
				System.out.println("target:"+target+"encode:"+encodeStr+",decode:"+decString+"\n,result:"+str2+","+str2.length());
			}
		}
		
		
	}
}
